import { Material } from './../../../../@core/data/material';
import { Component, Input } from '@angular/core';
import { TableWidthConfig } from 'ng-devui';
import { ProcessService } from 'src/app/@core/services/process/process.service';

@Component({
  selector: 'app-pre-viewm-mom',
  templateUrl: './pre-viewm-mom.component.html',
  styleUrls: ['./pre-viewm-mom.component.scss']
})
export class PreViewmMomComponent {
  nodes: any[] = [];
  @Input() data: any;
  tabActiveId = '工序'
  selectNode: any[] = [];
  MaterialTableData= []
  maxHeight = '400px';
  isClicked = false;
  devuiTableWidthConfig: TableWidthConfig[] = [
    {
      field: 'number',
      width: '120px',
    },
    {
      field: 'number',
      width: '120px'
    },
    {
      field: 'code',
      width: '120px'
    },
    {
      field:'name',
      width:'100px'
    },
    {
      field: 'consumption',
      width: '100px'
    },{
      field: 'loss',
      width: '100px'
    }
  ];//表格宽度配置
  devuiTableWidthConfig2: TableWidthConfig[] = [
    {
      field: 'number',
      width: '120px',
    },
    {
      field: 'number',
      width: '120px'
    },
    {
      field: 'code',
      width: '120px'
    },
    {
      field:'name',
      width:'100px'
    },
    {
      field: 'consumption',
      width: '100px'
    },{
      field: 'loss',
      width: '100px'
    },
    {
      field: 'consumption',
      width: '100px'
    },{
      field: 'loss',
      width: '100px'
    }
  ];//表格宽度配置
  constructor(private ProcessService:ProcessService) { }
  ngOnInit(): void {
    this.tabActiveId = this.data?.tabActiveId || '工序'
    this.nodes = this.data.nodes
    this.selectNode = this.nodes
    this.nodes.forEach(n => n.isClicked = false);
    this.MaterialTableData = this.nodes.flatMap(node => node.parts);
  }
  nodeClick(node: any) {
    // 如果当前点击的节点已经被选中，则切换 isClicked 为 false
    if (node.isClicked) {
        node.isClicked = false;
        this.selectNode = this.data.nodes;
        this.MaterialTableData = this.nodes.flatMap(node => node.parts);
    } else {
        // 否则，将所有节点的 isClicked 设置为 false
        this.nodes.forEach(n => n.isClicked = false);
        // 选中当前节点
        this.selectNode = [node];
        node.isClicked = true;
        this.MaterialTableData = node.parts;
    }
  }
}
